Dreamweaver Article

Implementing User Authentication


Table of Contents

  1. Introduction
  2. Setting Up The Site
  3. User Authentication as a Web Application
  4. Introducing Sessions and Session Variables
  5. Implementing Registration
  6. Implementing Log-on
  7. Enabling Sessions With Application.cfm (ColdFusion Only)
  8. Restricting Access to Pages
  9. Implementing Log Out

Restricting Access to Pages

By now, you have tested your registration and login pages, and they should work as expected. The only thing is, until you implement page restriction features to the pages you want to block access to, your registration and login framework is not very useful. In this task, you will add the server behaviors that prevent users from accessing pages, unless they've first logged in.

  1. Back in Dreamweaver, open secret.asp.

    This is one of the pages that users must log in to see.

  2. Click anywhere on the page. In the Server Behaviors panel, insert a User Authentication > Restrict Access to Page server behavior. In the Restrict Based On group, choose Username, Password, and Access Level.

    This dialog box not only lets you restrict access to the page; it also lets you restrict access to page based on a user's access level.

    Of course, since no such levels are defined in the Select Level(s) area, you must define some.

    The Restrict Access To Page dialog box

    Figure 9. The Restrict Access To Page dialog box

  3. Click the Define button. In the Define Access Levels dialog box, place the cursor in the Name field, type visitor, and press the + button. Repeat the process to add admin. Click OK.

    Dreamweaver won't check to make sure these groups actually exist; it takes your word for it, so make sure you spell them correctly. These correspond to the available values in the userGroup field of tbl_users. Once Dreamweaver knows the users' names, Dreamweaver can grant access to pages to users in either or both groups, and deny access to users not in either.

    The Define Access Levels dialog box

    Figure 10. The Define Access Levels dialog box

  4. Back in the Restrict Access to Page dialog box, Ctrl-click (Windows) or Command-click (Macintosh) to select both visitor and admin from the Select Level(s) area. In the If Access Denied, Go To field, enter login.asp. Click OK.

    The Restrict Access To Page dialog box

    Figure 11. The Restrict Access To Page dialog box

    You've done two things in this step. You've granted access to the page to users in either the visitor or admin group. Had you wanted to grant access to this page to only one of those groups, you would have selected only the one group. Once you've created the admin section of the site, you'll use this dialog box and to permit only members of the admin group.

    The other thing you've done is redirect the user to login.asp if access is denied. This is how that interception described earlier happens. A user tries to access a restricted page without logging in, and she or he sees the login dialog box. Once log-on is achieved, the restricted page she or he was trying to access appears.

  5. Repeat steps 1-4 for top_secret.asp, except grant access to top_secret.asp only to users in the admin group.

    This page now requires authentication as well.

  6. Save and upload all of the pages you have worked on in this lesson. Starting from the homepage (index.asp), try directly accessing secret.asp or top_secret.asp.

    The authentication framework is fully functional. If you try to access a protected page, the login screen will appear. If you've created a registration account, use it. Or, remember you can use username: osiris@allectomedia.com and password: osiris to test. Once you've logged in, the application will automatically redirect you to the page you first requested.

    The log-on that you created yourself should let you into secret.asp, but not top_secret.asp. Only admin users can access that page. On the login page, try the following credentials to get into top_secret.asp.

    zfrome@starknet.com
    hypochondriac

    Note: PHP users with PHP 4.2 and higher will be disappointed to learn that instead of being redirected to the originally requested page after log-on, the application sends them to the home page. The reason for this is that the server behavior that is supposed to cause the redirection to the originally requested page relies on a configuration setting, register_globals, that must be on for redirection. Since PHP 4.2, the default setting for register_globals is off. You can go into your php.ini file and change it to on and the site will work as expected. However, it was turned off for a reason—this setting creates a potential security hole in PHP. Thus, before you decide to go into php.ini and change the setting, I recommend that you research the issue on the web.